import 'package:base_flutter/base_flutter.dart';

class AxunUser{
  static String? userAccount;
  static String? userId;
  static String? accountId;
  static String? userName;
  static String? pdd;
  static String code = "130";
  static bool isLogin = false;
  static SpUtil? _instance;
  static String orgName = "";
  static Future<void> init() async {
    _instance = await SpUtil.getInstance();
     getUserInfo();
  }

  static Future<void> saveInfo(String userAccount,String userId,String userName,String pdd,String accountId) async {
    await SpUtil.putString("userName", userAccount);
    await SpUtil.putString("userId", userId);
    await SpUtil.putString("userName", userName);
    await SpUtil.putString("accountId", accountId);
    await SpUtil.putString("pdd", pdd);
    AxunUser.userAccount = userAccount;
    AxunUser.userId = userId;
    AxunUser.userName = userName;
    AxunUser.pdd = pdd;
    AxunUser.accountId = accountId;
  }

  static Future<void> saveCode(String code) async{
     await SpUtil.putString("code", code);
     AxunUser.code = code;
  }

  static void getUserInfo(){
    userId =  SpUtil.getString("userId");
    userAccount = SpUtil.getString("userAccount");
    userName = SpUtil.getString("userName");
    pdd = SpUtil.getString("pdd");
    accountId = SpUtil.getString("accountId");
    if(BuildConfig.isDebug){
      // AxunUser.code = '143';
      AxunUser.code = SpUtil.getString("code",defValue: "130")??"130";
    }else{
      AxunUser.code = SpUtil.getString("code",defValue: "130")??"130";
    }
    if(userId.isNullOrEmpty()){
      isLogin = false;
    }else{
      isLogin = true;
    }
  }

  static Future<void> clearUser() async {
    await SpUtil.putString("userName", "");
    await SpUtil.putString("userId", "");
    await SpUtil.putString("userName", "");
    await SpUtil.putString("accountId", "");
    await SpUtil.putString("pdd", "");
    AxunUser.userAccount = "";
    AxunUser.userId = "";
    AxunUser.userName = "";
    AxunUser.pdd = "";
    AxunUser.accountId = "";
    isLogin = false;
  }
}